/*
 * Copyright 2020-2030 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
*/

package com.gitee.minimalismstyle.fresh.flowable.api.feign

import org.springframework.web.bind.annotation.*
import com.gitee.minimalismstyle.fresh.common.core.domain.R
import com.gitee.minimalismstyle.fresh.flowable.api.annotation.FlowableClient
import com.gitee.minimalismstyle.fresh.flowable.api.config.FlowableFeignConfig
import com.gitee.minimalismstyle.fresh.flowable.api.feign.model.DataResponse
import com.gitee.minimalismstyle.fresh.flowable.api.feign.model.ModelRequest
import com.gitee.minimalismstyle.fresh.flowable.api.feign.model.ModelResponse
import org.springframework.http.MediaType
import org.springframework.web.multipart.MultipartFile

/**
 * Models
 * @author maoxiaodong
 */
@FlowableClient(configuration = [FlowableFeignConfig::class])
interface ModelsApi {


    /**
     * List models
     */
    @GetMapping("/repository/models")
    fun listModels(
        @RequestParam(name = "id", required = false) id: String?,
        @RequestParam(name = "category", required = false) category: String?,
        @RequestParam(name = "categoryLike", required = false) categoryLike: String?,
        @RequestParam(name = "categoryNotEquals", required = false) categoryNotEquals: String?,
        @RequestParam(name = "name", required = false) name: String?,
        @RequestParam(name = "nameLike", required = false) nameLike: String?,
        @RequestParam(name = "key", required = false) key: String?,
        @RequestParam(name = "deploymentId", required = false) deploymentId: String?,
        @RequestParam(name = "version", required = false) version: Int?,
        @RequestParam(name = "latestVersion", required = false) latestVersion: Boolean?,
        @RequestParam(name = "deployed", required = false) deployed: Boolean?,
        @RequestParam(name = "tenantId", required = false) tenantId: String?,
        @RequestParam(name = "tenantIdLike", required = false) tenantIdLike: String?,
        @RequestParam(name = "withoutTenantId", required = false) withoutTenantId: Boolean?,
        @RequestParam(name = "sort", required = false) sort: String?
    ): R<DataResponse<ModelResponse>>

    /**
     * All request values are optional. For example, you can only include the name attribute in the request body JSON-object, only setting the name of the model, leaving all other fields null.
     */
    @PostMapping("/repository/models")
    fun createModel(
        @RequestBody(required = false) body: ModelRequest?
    ): R<ModelResponse>

    /**
     * Get a model
     */
    @GetMapping("/repository/models/{modelId}")
    fun getModel(
        @PathVariable("modelId") modelId: String
    ): R<ModelResponse>

    /**
     * All request values are optional. For example, you can only include the name attribute in the request body JSON-object, only updating the name of the model, leaving all other fields unaffected. When an attribute is explicitly included and is set to null, the model-value will be updated to null.
     */
    @PutMapping("/repository/models/{modelId}")
    fun updateModel(
        @PathVariable("modelId") modelId: String,
        @RequestBody(required = false) body: ModelRequest?
    ): R<ModelResponse>

    /**
     * Delete a model
     */
    @DeleteMapping("/repository/models/{modelId}")
    fun deleteModel(
        @PathVariable("modelId") modelId: String
    ): R<Any>

    /**
     * Response body contains the model’s raw editor source. The response’s content-type is set to application/octet-stream, regardless of the content of the source.
     */
    @GetMapping("/repository/models/{modelId}/source")
    fun getModelBytes(
        @PathVariable("modelId") modelId: String
    ): R<Any>

    /**
     * Response body contains the model’s raw editor source. The response’s content-type is set to application/octet-stream, regardless of the content of the source.
     */
    @PutMapping(value = ["/repository/models/{modelId}/source"], consumes = [MediaType.MULTIPART_FORM_DATA_VALUE])
    fun setModelSource(
        @PathVariable("modelId") modelId: String,
        @RequestParam(name = "file", required = true) file: MultipartFile
    ): R<Any>

    /**
     * Response body contains the model’s raw editor source. The response’s content-type is set to application/octet-stream, regardless of the content of the source.
     */
    @GetMapping("/repository/models/{modelId}/source-extra")
    fun getExtraEditorSource(
        @PathVariable("modelId") modelId: String
    ): R<Any>

    /**
     * Response body contains the model’s raw editor source. The response’s content-type is set to application/octet-stream, regardless of the content of the source.
     */
    @PutMapping(value = ["/repository/models/{modelId}/source-extra"], consumes = [MediaType.MULTIPART_FORM_DATA_VALUE])
    fun setExtraEditorSource(
        @PathVariable("modelId") modelId: String,
        @RequestParam(name = "file", required = true) file: MultipartFile
    ): R<Any>
}